using System;
using System.Collections.Generic;
using System.Text;

using NHibernate;
using NHibernate.Data.Models;
using NHibernate.Data.Base;

namespace NHibernate.Data.Managers
{
    public partial interface IReWineGrapeVarietyManager : IManagerBase<ReWineGrapeVariety, string>
    {
		// Get Methods
		ReWineGrapeVariety GetById(System.Int64 wine, System.Int64 grapeVariety);
    }

    partial class ReWineGrapeVarietyManager : ManagerBase<ReWineGrapeVariety, string>, IReWineGrapeVarietyManager
    {
		#region Constructors
		
		public ReWineGrapeVarietyManager() : base()
        {
        }
        public ReWineGrapeVarietyManager(INHibernateSession session) : base(session)
        {
        }
		
		#endregion
		
        #region Get Methods

		public override ReWineGrapeVariety GetById(string id)
		{
			string[] keys = id.Split('^');
			
			if(keys.Length != 2)
				throw new Exception("Invalid Id for ReWineGrapeVarietyManager.GetById");
			
			return GetById(System.Int64.Parse(keys[0]), System.Int64.Parse(keys[1]));
		}
		public ReWineGrapeVariety GetById(System.Int64 wine, System.Int64 grapeVariety)
		{
			ICriteria criteria = Session.GetISession().CreateCriteria(typeof(ReWineGrapeVariety));
			
			criteria.Add(NHibernate.Criterion.Expression.Eq("Wine", wine));
			criteria.Add(NHibernate.Criterion.Expression.Eq("GrapeVariety", grapeVariety));
			
			ReWineGrapeVariety result = (ReWineGrapeVariety)criteria.UniqueResult();

            if (result == null)
                throw new NHibernate.ObjectDeletedException("", null, null);

            return result;
		}
		
		
		#endregion
    }
}